# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Mitch Bigelow <ipha00@gmail.com>

pkgname=waifu2x-ncnn-vulkan
pkgver=20220728
pkgrel=2
pkgdesc="ncnn implementation of waifu2x converter"
url="https://github.com/nihui/waifu2x-ncnn-vulkan"
license=('MIT')
arch=('loong64' 'x86_64')
depends=('libwebp' 'ncnn')
makedepends=('cmake' 'glslang' 'vulkan-headers')
conflicts=('waifu2x-ncnn-vulkan-git')
source=("https://github.com/nihui/waifu2x-ncnn-vulkan/archive/$pkgver/$pkgname-$pkgver.tar.gz")
sha256sums=('c3dcd3b4e3ebb7ac64ddfc0714c065432dbf385a1928fb95d6dea5cc307ced47')

prepare() {
    mkdir -p build

    cd waifu2x-ncnn-vulkan-$pkgver
    # Fix default model path
    sed -i 's|path_t model = PATHSTR("models-cunet")|path_t model = PATHSTR("/usr/share/waifu2x-ncnn-vulkan/models-cunet")|' src/main.cpp
}

build() {
    cd build
    cmake -DCMAKE_INSTALL_PREFIX=/usr -DUSE_SYSTEM_NCNN=ON -DUSE_SYSTEM_WEBP=ON -DGLSLANG_TARGET_DIR=/usr/lib/cmake ../waifu2x-ncnn-vulkan-$pkgver/src
    make
}

package() {
    install -Dm644 waifu2x-ncnn-vulkan-$pkgver/LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
    install -Dm755 build/waifu2x-ncnn-vulkan -t "$pkgdir"/usr/bin/

    cd waifu2x-ncnn-vulkan-$pkgver/models
    for f in models-*/*; do
        install -Dm644 "$f" ${pkgdir}/usr/share/waifu2x-ncnn-vulkan/"$f"
    done
}
